package com.example.controller;

import com.example.config.Result;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "邮件")
public class EmailController {
//    @Autowired
//    private EmailService emailService;

    @Value("${spring.mail.username}")
    private String from;
    @Autowired
    private JavaMailSender javaMailSender;

    @GetMapping("/email")
    public Result<?> email(@RequestParam(value = "emailName")String emailName,
                           @RequestParam(value = "emailNumber")String emailNumber,
                           @RequestParam(value = "emailTitle")String emailTitle,
                           @RequestParam(value = "emailContent")String emailContent){

        SimpleMailMessage email = new SimpleMailMessage();
        email.setFrom(from);
        email.setText(emailName);
        email.setTo(emailNumber);
        email.setSubject(emailTitle);
        email.setText(emailContent);
        javaMailSender.send(email);
        return Result.success();
    }



}
